// pages/my/myResume/shopResume.js
const TABLENAME = "shopmanData"
const db = wx.cloud.database()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		_id: "",
		trigger: true,
		myresume: {
			name: '',
			gender: '',
			age: '',
			company: "",
			phone: '',
			email: '',
			address: '',
			prefer: [],
			experience: '',
			selfReview: '',
		}
	},

	changeTrigger: function (e) {
		//save
		const db = wx.cloud.database()
		db.collection(TABLENAME).doc(this.data._id).update({
			// data 传入需要局部更新的数据
			data: {
				name: e.detail.name,
				gender: e.detail.gender,
				age: e.detail.age,
				company: e.detail.company,
				phone: e.detail.phone,
				email: e.detail.email,
				address: e.detail.address,
				prefer: e.detail.prefer,
				experience: e.detail.experience,
				selfReview: e.detail.selfReview,
			},
			success: function (res) {
				console.log(res.data)
			}
		})

		if (!e.currentTarget.id) { //子组件触发事件, 切换回myresume
			this.setData({
				trigger: true,
				myresume: e.detail
			})
			console.log(this.data.myresume);
		} else {
			this.setData({
				trigger: false
			})
		}
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		const OPENID = wx.getStorageSync('userOpenid').OPENID

		db.collection(TABLENAME).where({
			_openid: OPENID
		}).get({
			success: res => {
				console.log(res.data[0])
				this.setData({
					_id: res.data[0]._id,
					myresume: {
						gender: res.data[0].gender,
						age: res.data[0].age,
						company: res.data[0].company,
						phone: res.data[0].phone,
						email: res.data[0].email,
						address: res.data[0].address,
						company:res.data[0].company,
						prefer: res.data[0].prefer,
						experience: res.data[0].experience,
						selfReview: res.data[0].selfReview,
						name: res.data[0].name,
					},
				})
				console.log(this.data.myresume)
			}
		})
	},

})